/**
 * 发电登记
 * @author chenpeng
 * @date 2017.6.6
 */
var localObj = window.location;
var contextPath = localObj.pathname.split("/")[1];
var basePath = localObj.protocol + "//" + localObj.host + "/" + contextPath;

var Ele66 = {
		
	queryList : function(){
		var _this = this;
		var s_create_time = $("#s_create_time").val();
		var e_create_time = $("#e_create_time").val();
		var order_code = $("#s_order_code").val();
		var contact_number = $("#s_contact_number").val();
		var company_id = $("#s_company_id").combobox("getValue");
		var area_id = $("#s_area_id").combobox("getValue");
		var station_name = $("#s_station_name").val();
		$("#tt").datagrid({
			url: basePath + '/ele/queryResult.a',
			queryParams:{
				"s_create_time":s_create_time,
				"e_create_time":e_create_time,
				"order_code":order_code,
				"company_id":company_id,
				"area_id":area_id,
				"station_name":station_name,
				"state":1
			},
			height: ($(window).height()*0.98),
			//height: $(window).height(),
            singleSelect:true, 
	        rownumbers:true,
	        remoteSort:true,
	        idField: 'id',
	        frozenColumns:[[ 
	            {field:'ck',checkbox:true} 
	        ]],
	        columns:[[ 
				{field:'id',title:'id',width:'100',align:'center',sortable:true,hidden:true},
				{field:'create_time',title:'日期',width:'110',align:'center',sortable:true,hidden:false},
				{field:'company_id',title:'分公司',width:'10',align:'center',sortable:false,hidden:true},
				{field:'company_name',title:'分公司',width:'110',align:'center',sortable:false,hidden:true},
				{field:'area_id',title:'区域',width:'10',align:'center',sortable:false,hidden:true},
				{field:'area_name',title:'区域',width:'120',align:'center',sortable:true,hidden:false},
				{field:'station_id',title:'局站名称',width:'100',align:'center',sortable:true,hidden:true},
				{field:'station_name',title:'局站名称',width:'100',align:'center',sortable:true,hidden:false},
				{field:'start_time',title:'开始发电时间',width:'120',align:'center',sortable:true,hidden:false},
				{field:'start_photo',title:'开始照片',width:'100',align:'center',sortable:true,hidden:false},
				{field:'end_time',title:'结束发电时间',width:'120',align:'center',sortable:true,hidden:false},
				{field:'end_photo',title:'结束照片',width:'100',align:'center',sortable:true,hidden:false},
				{field:'engine_id',title:'油机号',width:'100',align:'center',sortable:true,hidden:true},
				{field:'plate_number',title:'油机号',width:'100',align:'center',sortable:true,hidden:false},
				{field:'contact_number',title:'电话',width:'100',align:'center',sortable:false,hidden:false},
				{field:'start_affirm',title:'开始确认',width:'100',align:'center',sortable:true,hidden:false},
				{field:'end_affirm',title:'结束确认',width:'100',align:'center',sortable:true,hidden:false},
				{field:'station_type_id',title:'局站类型',width:'100',align:'center',sortable:false,hidden:true},
				{field:'station_type',title:'局站类型',width:'100',align:'center',sortable:false,hidden:false},
				{field:'network_id',title:'网管',width:'80',align:'center',sortable:false,hidden:true},
				{field:'network_name',title:'网管',width:'80',align:'center',sortable:false,hidden:false},
				{field:'node_id',title:'节点信息',width:'90',align:'center',sortable:false,hidden:true},
				{field:'node',title:'节点信息',width:'90',align:'center',sortable:false,hidden:false},
				{field:'room_attribute_id',title:'机房属性',width:'100',align:'center',sortable:false,hidden:true},
				{field:'room_attribute',title:'机房属性',width:'100',align:'center',sortable:false,hidden:false},
				{field:'derect_voltage',title:'派单电压',width:'100',align:'center',sortable:true,hidden:false},
				{field:'poweroff_time',title:'停电时间',width:'120',align:'center',sortable:true,hidden:false},
				{field:'user_id',title:'派单人',width:'90',align:'center',sortable:true,hidden:true},
				{field:'user_name',title:'派单人',width:'90',align:'center',sortable:false,hidden:false},
				{field:'generation_minutes',title:'发电时长(min)',width:'100',align:'center',sortable:true,hidden:false},
				{field:'generation_fee',title:'发电油耗(L)',width:'100',align:'center',sortable:true,hidden:false},
				{field:'order_code',title:'工单号',width:'100',align:'center',sortable:true,hidden:false},
				{field:'ext1',title:'备注/预留',width:'100',align:'center',sortable:false,hidden:false},
				{field:'ext2',title:'预留2',width:'100',align:'center',sortable:false,hidden:false},
				{field:'update_time',title:'更新时间',width:'120',align:'center',sortable:true,hidden:false}
		    ]],
		    pagination: true,
		    pageSize: 50,  
	        pageList: [20,50,100],
			onBeforeLoad:function(){
				//$(this).datagrid('rejectChanges');
			},
			onSortColumn:function(sort,order){
				var queryParams = $('#tt').datagrid('options').queryParams;
				queryParams.sidx = sort;
				queryParams.sord = order;
			},
		});
		//设置分页控件  
	    var p = $('#tt').datagrid('getPager');  
	    $(p).pagination({
	    	//pageSize和pageList写在datagrid里，否则分页rows初始值总默认为10
	        //pageSize: 50,
	        //pageList: [20,50,100],  
	        beforePageText: '第',
	        afterPageText: '页    共 {pages} 页',  
	        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'  
	    });
	},
	
	findData : function(){
		//alert($("#sdata").serialize());
		var _this = this;
		_this.queryList();
	},
	
	//重置查询条件
	clearSData : function(){
		//s_create_time e_create_time
		var _this = this;
		$("#s_create_time").val(_this.getDateStr(new Date(),-2));
		$("#e_create_time").val(_this.getDateStr(new Date(),0));
		$("#s_order_code").val('');
		$("#contact_number").val('');
		$("#s_company_id").combobox("setValue","");
		$("#s_area_id").combobox("setValue","");
		$("#s_station_name").val('');
		_this.queryList();
	},
	
	exportData : function(){
		var s_create_time = $("#s_create_time").val();
		var e_create_time = $("#e_create_time").val();
		var order_code = $("#s_order_code").val();
		var contact_number = $("#s_contact_number").val();
		var company_id = $("#s_company_id").combobox("getValue");
		var area_id = $("#s_area_id").combobox("getValue");
		var station_name = $("#s_station_name").val();
		var postParams = "s_create_time=" + encodeURIComponent(s_create_time);
		postParams += "&e_create_time=" + encodeURIComponent(e_create_time);
		postParams += "&order_code=" + encodeURIComponent(order_code);
		postParams += "&contact_number=" + encodeURIComponent(contact_number);
		postParams += "&company_id=" + encodeURIComponent(company_id);
		postParams += "&area_id=" + encodeURIComponent(area_id);
		postParams += "&station_name=" + encodeURIComponent(station_name);
		window.location.href = basePath + "/ele/exportData.a?" + postParams;
	},
	
	//初始化查询条件，加载查询条件-分公司、区域、局站列表
	initSData : function(){
		var _this = this;
		$("#s_company_id").combobox({
			url : basePath + '/jsp/share/load_company.jsp',
			valueField : 'id',
			textField : 'text',
			//editable : false,
			onChange : function(){
				var company_id = $("#s_company_id").combobox("getValue");
				_this.loadSArea(company_id);
			}
		});
	},
	
	loadSArea : function(company_id){
		var _this = this;
		$("#s_area_id").combobox({
			url : basePath + '/jsp/share/load_area.jsp?company_id=' + company_id,
			valueField : 'id',
			textField : 'text'
		});
	},
	
	loadSStation : function(area_id){
		$("#s_station_id").combobox({
			url : basePath + '/jsp/share/load_station.jsp?area_id=' + area_id,
			valueField : 'id',
			textField : 'text',
			//editable : false,
			onLoadSuccess:function(){
			}
		});
	},
	
	initFormData : function(){
		var _this = this;
		_this.loadCompany();
		_this.loadEngine(1);
		_this.loadNetwork();
		_this.loadNode();
		_this.loadRoomAttr();
		_this.loadStationType();
	},
	
	deleteData : function(){
		var _this = this;
		var rows = $("#tt").datagrid("getSelections");
		if(rows.length != 1){
			$.messager.alert("操作提示", "请选择一项进行操作！","info");
			//return false;
			return ;
		}
//		var create_time = Date.parse(new Date(rows[0].create_time.replace(/-/g, "/")));
//		alert(new Date(create_time).getDate());
//		alert(new Date().getDate());
//		alert(new Date().getDate() - new Date(create_time).getDate() >= 3);
//		var session_user_id = $("#session_user_id").val();
//		var user_role = $("#user_role").val();
//		if(parseInt(user_role) != 1){//非管理员
//			if(session_user_id != rows[0].user_id){
//				$.messager.alert("操作提示", "只能删除本人登记的发电记录！","info");
//				return ;
//			}
//			var create_time = Date.parse(new Date(rows[0].create_time.replace(/-/g, "/")));
//			/*if (new Date(create_time).toDateString() != new Date().toDateString()) {
//				$.messager.alert("操作提示", "只能删除当天登记的发电记录！","info");
//				return ;
//			}*/ 
//			if (new Date().getDate() - new Date(create_time).getDate() >= 3) {
//				$.messager.alert("操作提示", "只能删除三天以内登记的发电记录！","info");
//				return ;
//			} 
//		}
		$.ajax({
			type : 'post',
			url : basePath + '/ele/deleteById.a',
			data : {'id' : rows[0].id},
			dataType : 'json',
			async : false,
			success : function(data){
				if(data.errMsg == "success"){
					$.messager.alert("操作提示", "操作成功！","info",function(){
						_this.queryList();
					});
				} else {
					$.messager.alert("操作提示", "操作失败！","error");
				}
			}
		});
	},
	
	copyData : function(type){
		var _this = this;
		var rows = $("#tt").datagrid("getSelections");
		if(rows.length != 1){
			$.messager.alert("操作提示", "请选择一项进行操作！","info");
			return ;
		}
		var tocopy = '';
		if(type == 1){
			//派单复制
			var area_name = rows[0].area_name;//区域
			//area_name = area_name.substring(3);
			var station_name = rows[0].station_name;//局站名称
			var station_type = rows[0].station_type;//局站类型
			var node = rows[0].node;//节点信息
			var derect_voltage = rows[0].derect_voltage;//派单电压
			tocopy = area_name + '*' + station_name + '*' + station_type + '*' + node + '*停电' + derect_voltage;
		} else if(type == 2){
			//闭单复制
			var min = rows[0].generation_minutes;
			if(min){
				var start_time = rows[0].start_time;
				var end_time = rows[0].end_time;
				tocopy = "确认油机发电结束（开始" + start_time + "--结束" + end_time + "）";
			} else {
				tocopy = "未发电工单闭环";
			}
		}
		$("#copyData").val(tocopy);
		$("#copyData").click();
	},
	
	toModify : function(){
		var _this = this;
		var rows = $("#tt").datagrid("getSelections");
		if(rows.length != 1){
			$.messager.alert("操作提示", "请选择一项进行操作！","info");
			return;
		}
		
		var session_user_id = $("#session_user_id").val();
		var user_role = $("#user_role").val();
		if(parseInt(user_role) != 1){//非管理员
			/*if(session_user_id != rows[0].user_id){
				$.messager.alert("操作提示", "只能修改本人登记的发电记录！","info");
				return;
			}*/
			var create_time = Date.parse(new Date(rows[0].create_time.replace(/-/g, "/")));
			/*if (new Date(create_time).toDateString() != new Date().toDateString()) {
				$.messager.alert("操作提示", "只能修改当天登记的发电记录！","info");
				return;
			} */
			if (new Date().getDate() - new Date(create_time).getDate() >= 3) {
				$.messager.alert("操作提示", "只能修改三天以内登记的发电记录！","info");
				return ;
			} 
		}
		_this.initFormData();
		//_this.clearFormData();
		$("#id").val(rows[0].id);
		$("#create_time").val(rows[0].create_time);
		$("#company_id").combobox("setValue",rows[0].company_id);
		$("#area_id").combobox("setValue",rows[0].area_id);
		$("#network_id").combobox("setValue",rows[0].network_id);
		$("#node_id").combobox("setValue",rows[0].node_id);
		$("#room_attribute_id").combobox("setValue",rows[0].room_attribute_id);
		$("#station_type_id").combobox("setValue",rows[0].station_type_id);
		$("#station_id").combobox("setValue",rows[0].station_id);
		$("#derect_voltage").val(rows[0].derect_voltage);
		$("#poweroff_time").val(rows[0].poweroff_time);
		$("#engine_id").combobox("setValue",rows[0].engine_id);
		$("#start_time").val(rows[0].start_time);
		//$("#start_affirm").val(rows[0].start_affirm);
		$("#start_affirm").combobox("setValue",rows[0].start_affirm);
		//$("input[name='start_photo'][value='" + rows[0].start_photo + "']").attr("checked",true);
		$("#start_photo").val(rows[0].start_photo);
		$("#end_time").val(rows[0].end_time);
		//$("#end_affirm").val(rows[0].end_affirm);
		$("#end_affirm").combobox("setValue",rows[0].end_affirm);
		//$("input[name='end_photo'][value='" + rows[0].end_photo + "']").attr("checked",true);
		$("#end_photo").val(rows[0].end_photo);
		//$("#generation_minutes").val(rows[0].generation_minutes);
		//$("#generation_fee").val(rows[0].generation_fee);
		$("#contact_number").val(rows[0].contact_number);
		$("#order_code").val(rows[0].order_code);
		$("#ext1").val(rows[0].ext1);
		$("#ext2").val(rows[0].ext2);
 		$('#dlg').window('open');
	},
	
	toAddStation : function(){
		var _this = this;
		$("#st_area_id").combobox("setValue","");
		_this.loadStCompany();
		_this.loadStStationType();
		$("#st_station_name").val("");
		$('#station_dlg').window('open');
	},
	
	addStation : function(){
		$.ajax({
			url : basePath + "/station/addStation.a",
			type : "post",
			data : $("#stationData").serialize(),
			dataType : "json",
			async : false,
			success : function(data){
				if(data.errMsg == "success"){
					$.messager.alert("操作提示", "操作成功！","info",function(){
						$("#station_dlg").dialog("close");
						_this.queryList();
					});
				} else {
					$.messager.alert("操作提示", data.errCode,"error");
				}
			},
			error : function(e){
				alert(JSON.stringify(e));
			}
		});
	},
	
	toAdd : function(){
		var _this = this;
		
		_this.initFormData();
		_this.clearFormData();
		$("#network_id").combobox("setValue","1");
		$("#node_id").combobox("setValue","1");
		$("#room_attribute_id").combobox("setValue","1");
		$("#station_type_id").combobox("setValue","4");
		$("#start_photo").val("");
		$("#end_photo").val("");
		/*$("#start_photo1").removeAttr("checked");
		$("#start_photo2").removeAttr("checked");
		$("#start_photo0").prop("checked","checked");
		$("#end_photo1").removeAttr("checked");
		$("#end_photo2").removeAttr("checked");
		$("#end_photo0").prop("checked","checked");*/
		//$("input:radio[name='start_photo']").eq(0).attr("checked",'checked');
		//$("input:radio[name='end_photo']").eq(0).attr("checked",'checked');
		$('#dlg').window('open');
	},
	
	validate : function(){
		if($("#company_id").combobox("getValue") == ''){
			$.messager.alert("操作提示", "请选择分公司！","info");
			return false;
		}
		if($("#area_id").combobox("getValue") == ''){
			$.messager.alert("操作提示", "请选择所属区域！","info");
			return false;
		}
		if($("#network_id").combobox("getValue") == ''){
			$.messager.alert("操作提示", "请选择网管！","info");
			return false;
		}
		if($("#node_id").combobox("getValue") == ''){
			$.messager.alert("操作提示", "请选择节点信息！","info");
			return false;
		}
		if($("#room_attribute_id").combobox("getValue") == ''){
			$.messager.alert("操作提示", "请选择机房产权！","info");
			return false;
		}
		if($("#station_type_id").combobox("getValue") == ''){
			$.messager.alert("操作提示", "请选择局站类型！","info");
			return false;
		}
		if($("#station_id").combobox("getValue") == ''){
			$.messager.alert("操作提示", "请选择局站名称！","info");
			return false;
		}
		if($("#derect_voltage").val() == ''){
			$.messager.alert("操作提示", "请输入派单电压！","info");
			return false;
		}
		if($("#poweroff_time").val() == ''){
			$.messager.alert("操作提示", "请输入停电时间！","info");
			return false;
		}
		return true;
	},
	
	addEle : function(){
		var _this = this;
		//alert($("#eleData").serialize());
		if(_this.validate()){
			$.ajax({
				url : basePath + "/ele/addEleRegistration.a",
				type : "post",
				data : $("#eleData").serialize(),
				dataType : "json",
				async : false,
				success : function(data){
					if(data.errMsg == "success"){
						$.messager.alert("操作提示", "操作成功！","info",function(){
							$("#dlg").dialog("close");
							_this.queryList();
						});
					} else {
						$.messager.alert("操作提示", data.errCode,"error");
					}
				},
				error : function(e){
					alert(JSON.stringify(e));
				}
			});
		}
	},
	
	//加载添加站点的分公司
	loadStCompany : function(){
		var _this = this;
		$("#st_company_id").combobox({
			url : basePath + '/jsp/share/load_company.jsp',
			valueField : 'id',
			textField : 'text',
			editable : false,
			onChange : function(){
				var company_id = $("#st_company_id").combobox("getValue");
				_this.loadStArea(company_id);
			}
		});
	},
	
	loadStArea : function(company_id){
		$("#st_area_id").combobox({
			url : basePath + '/jsp/share/load_area.jsp?company_id=' + company_id,
			valueField : 'id',
			textField : 'text',
			editable : false,
			onLoadSuccess:function(){
				$("#st_area_id").combobox("setValue","");
			},
			onChange : function(){
				var area_name = $("#st_area_id").combobox("getText");
				$("#st_area_name").val(area_name);
			}
		});
	},
	
	loadStStationType : function(){
		var _this = this;
		$("#st_station_type_id").combobox({
			url : basePath + '/jsp/share/load_station_type.jsp',
			valueField : 'id',
			textField : 'text',
			editable : false,
			onChange : function(){
				var station_type = $("#st_station_type_id").combobox("getText");
				$("#st_station_type").val(station_type);
			}
		});
	},
	
	//加载派单的分公司
	loadCompany : function(){
		var _this = this;
		$("#company_id").combobox({
			url : basePath + '/jsp/share/load_company.jsp',
			valueField : 'id',
			textField : 'text',
			editable : false,
			onChange : function(){
				var company_id = $("#company_id").combobox("getValue");
				//alert(company_id + "," + $("#company_id").combobox("getText"));
				//var area_id = $("#area_id").combobox("getValue");
				//var station_type_id = $("#station_type_id").combobox("getValue");
				_this.loadEngine(company_id);
				_this.loadArea(company_id);
				//_this.loadStation();
			}
		});
		//$("#company_id").combobox("setValue","1");
	},
	
	loadEngine : function(company_id){
		var _this = this;
		$("#engine_id").combobox({
			url : basePath + '/jsp/share/load_engine.jsp?company_id=' + company_id,
			valueField : 'id',
			textField : 'text'
		});
	},
	
	loadArea : function(company_id){
		var _this = this;
		$("#area_id").combobox({
			url : basePath + '/jsp/share/load_area.jsp?company_id=' + company_id,
			valueField : 'id',
			textField : 'text',
			editable : false,
			onChange : function(){
				//var company_id = $("#company_id").combobox("getValue");
				//var area_id = $("#area_id").combobox("getValue");
				//var station_type_id = $("#station_type_id").combobox("getValue");
				//alert("area_id:" + area_id + ",station_type_id:" + station_type_id);
				_this.loadStation();
			}/*,
			onSelect : function(){
				_this.loadStation();
			}*/
		});
	},
	
	loadNetwork : function(){
		$("#network_id").combobox({
			url : basePath + '/jsp/share/load_network.jsp',
			valueField : 'id',
			textField : 'text',
			editable : false,
			onLoadSuccess:function(){
				//$("#network_id").combobox("setValue","1");
			}
		});
	},
	
	loadRoomAttr : function(){
		$("#room_attribute_id").combobox({
			url : basePath + '/jsp/share/load_roomattr.jsp',
			valueField : 'id',
			textField : 'text',
			editable : false,
			onLoadSuccess:function(){
				//$("#room_attribute_id").combobox("setValue","1");
			}
		});
	},
	
	loadNode : function(){
		$("#node_id").combobox({
			url : basePath + '/jsp/share/load_node.jsp',
			valueField : 'id',
			textField : 'text',
			editable : false,
			onLoadSuccess:function(){
				//$("#node_id").combobox("setValue","1");
			}
		});
	},
	
	loadStationType : function(){
		var _this = this;
		$("#station_type_id").combobox({
			url : basePath + '/jsp/share/load_station_type.jsp',
			valueField : 'id',
			textField : 'text',
			editable : false,
			onChange : function(){
//				var company_id = $("#company_id").combobox("getValue");
//				var area_id = $("#area_id").combobox("getValue");
//				var station_type_id = $("#station_type_id").combobox("getValue");
//				alert("area_id:" + area_id + ",station_type_id:" + station_type_id);
//				_this.loadStation(area_id,station_type_id);
				_this.loadStation();
			}
		});
	},
	
	loadStation : function(){
		//var company_id = $("#company_id").combobox("getValue");
		var area_id = $("#area_id").combobox("getValue");
		var station_type_id = $("#station_type_id").combobox("getValue");
		//alert(area_id + "," + station_type_id);
		$("#station_id").combobox({
			//url : basePath + '/jsp/share/load_station.jsp?company_id=' + company_id + '&area_id=' + area_id + '&station_type_id=' + station_type_id,
			url : basePath + '/jsp/share/load_station.jsp?area_id=' + area_id + '&station_type_id=' + station_type_id,
			valueField : 'id',
			textField : 'text',
			//editable : false,
			onLoadSuccess:function(){
			}
		});
	},
	
	loadStartAffirm : function(){
		$("#start_affirm").combobox({
			url : basePath + '/jsp/share/load_affirm.jsp?type=0',
			valueField : 'id',
			textField : 'text',
			editable : false,
			onLoadSuccess:function(){
			}
		});
	},
	
	loadEndAffirm : function(){
		$("#end_affirm").combobox({
			url : basePath + '/jsp/share/load_affirm.jsp?type=1',
			valueField : 'id',
			textField : 'text',
			editable : false,
			onLoadSuccess:function(){
			}
		});
	},
	
	//清空表单数据
	clearFormData : function(){
		var _this = this;
		$("#id").val('');
		$("#create_time").val(_this.getNowtime());
		$("#company_id").combobox("setValue","1");
		$("#area_id").combobox("setValue","");
		$("#network_id").combobox("setValue","");
		$("#room_attribute_id").combobox("setValue","");
		$("#node_id").combobox("setValue","");
		$("#station_type_id").combobox("setValue","");
		$("#station_id").combobox("setValue","");
		$("#derect_voltage").val("");
		$("#poweroff_time").val(_this.getNowtime());
		$("#engine_id").combobox("setValue","");
		$("#start_time").val("");
		$("#start_affirm").combobox("setValue","");
		$("#contact_number").val("");
		$("#end_time").val("");
		$("#end_affirm").combobox("setValue","");
		//$("#generation_minutes").val("");
		//$("#generation_fee").val("");
		$("#order_code").val("");
		$("#ext1").val("");
		$("#ext2").val("");
	},
	
	closeDig : function(){
		$("#dlg").dialog("close");
	},
	closeStDig : function(){
		$("#station_dlg").dialog("close");
	},
	
	//计算发电时长（分钟）
	calEleMin : function(){
		var _this = this;
		
		if($("#start_time").val() == ''){
			$.messager.alert("操作提示", "请填写开始发电时间！","info");
			return false;
		}
		if($("#end_time").val() == ''){
			$.messager.alert("操作提示", "请填写结束发电时间！","info");
			return false;
		}
		var start_time = Date.parse(new Date($("#start_time").val().replace(/-/g, "/")));
		var end_time = Date.parse(new Date($("#end_time").val().replace(/-/g, "/")));
		var mins = (end_time - start_time)/1000/60;
		//alert(start_time + "," + end_time + "," + mins);
		$("#generation_minutes").val(mins);
		/*var start_time = $("#start_time");
		var end_time = $("#end_time");
		if (!!window.ActiveXObject || "ActiveXObject" in window){
			start_time.onpropertychange = _this.doCal(); 
			end_time.onpropertychange = _this.doCal(); 
		} else { 
			start_time.addEventListener("input",_this.doCal(),false); 
			end_time.addEventListener("input",_this.doCal(),false); 
		}*/ 
	},
	
	calEleOil : function(){
		var engine_id = $("#engine_id").combobox("getValue");
		if(engine_id == ''){
			$.messager.alert("操作提示", "请选择油机！","info");
			return false;
		}
		if($("#start_time").val() == ''){
			$.messager.alert("操作提示", "请填写开始发电时间！","info");
			return false;
		}
		if($("#end_time").val() == ''){
			$.messager.alert("操作提示", "请填写结束发电时间！","info");
			return false;
		}
		var start_time = Date.parse(new Date($("#start_time").val().replace(/-/g, "/")));
		var end_time = Date.parse(new Date($("#end_time").val().replace(/-/g, "/")));
		var hours = (end_time - start_time)/1000/60/60;
		$.ajax({
			type : 'post',
			url : basePath + '/ele/queryOilEngineById.a',
			data : {'engine_id' : engine_id},
			dataType : 'json',
			async : false,
			success : function(data){
				if(data.errMsg = "success"){
					var generation_fee = data.fuel_consumption * hours;
					$("#generation_fee").val(Math.round(generation_fee*100)/100);
				}
			}
		});
	},
	
	reloadData : function(){
		window.document.location.reload();
	},
	
	//获取某一日期日期前后N天的日期
	getDateStr : function(dd,N) {
		dd.setDate(dd.getDate() + N);
		var y = dd.getFullYear();   
		var m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1);  
		var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();  
		return y + "-" + m + "-" + d;   
	},
	
	//获取当前时间
	getNowtime : function(){
		var _this = this;
		var nowtime = new Date();  
        var year = nowtime.getFullYear();  
        var month = _this.padleft0(nowtime.getMonth() + 1);  
        var day = _this.padleft0(nowtime.getDate());  
        var hour = _this.padleft0(nowtime.getHours());  
        var minute = _this.padleft0(nowtime.getMinutes());  
        //var second = _this.padleft0(nowtime.getSeconds());  
        //var millisecond = nowtime.getMilliseconds(); millisecond = millisecond.toString().length == 1 ? "00" + millisecond : millisecond.toString().length == 2 ? "0" + millisecond : millisecond;  
        //return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "." + millisecond;
        return year + "-" + month + "-" + day + " " + hour + ":" + minute;
	},
	
	//补齐两位数
	padleft0 : function(obj) {  
        return obj.toString().replace(/^[0-9]{1}$/, "0" + obj);  
    } 
};